const path = require("path")

module.exports = {
  publicPath: "./",
  lintOnSave: true,
  chainWebpack: (config) => {
    const types = ["vue-modules", "vue", "normal-modules", "normal"]
    types.forEach((type) => addStyleResource(config.module.rule("less").oneOf(type)))
    config.resolve.alias.set("@", path.resolve("src"))
  },
  configureWebpack: {
    resolve: {
      alias: {
        "@views": "@/views/",
        "@apis": "@/apis/",
        "@imgs": "@/images/",
        "@constant": "@/constants/",
        "@component": "@/components/",
        "@assets": "@/assets/"
      }
    }
  },
  devServer: {
    port: 8686,
    proxy: {
      "/diyring/api": {
        target: "https://vrbt.yn.iflytektstd.com",
        changeOrigin: true,
        pathRewrite: {},
        headers: {},
        pathRewrite: {
          "^/diyring/api": "/diyring/api"
        }
      },
    },
  }
}

function addStyleResource(rule) {
  rule
    .use("style-resource")
    .loader("style-resources-loader")
    .options({
      patterns: [path.resolve(__dirname, "./src/assets/css/global.less")],
    })
}